package com.rtx.edi.platform.dash.error.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rtx.edi.model.error.po.ApiOrders;
import com.rtx.edi.model.response.EdiResponse;
import com.rtx.edi.platform.dash.error.service.PlApiOrdersService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = {"出库单错误信息"})
@RestController
@RequestMapping("/v1/plApiOrdersError")
public class PlApiOrdersErrorController {
	
	@Autowired
	private PlApiOrdersService plApiOrdersService;
	
	@ApiOperation(value = "出库单错误信息列表", notes = "分页获取出库单错误信息")
    @PostMapping("qryApiOrdersError")
	public EdiResponse qryApiOrdersError(@RequestBody ApiOrders dto) {
		Page<ApiOrders>  pageParam = new Page<>(dto.getPageNum(),dto.getPageSize());
		plApiOrdersService.selectApiOrdersErrorList("ris_edi",pageParam, dto);
		return EdiResponse.success().data("page",pageParam);
	
	}
	
	@ApiOperation(value = "出库单错误信列表", notes = "根据id查询出库单错误信息")
    @PostMapping("qryApiOrdersErrorById")
	public EdiResponse qryApiOrdersErrorById(@RequestBody ApiOrders dto) {
		return EdiResponse.success().data("item",plApiOrdersService.getById(dto.getSerialkey()));

	}
	
	@ApiOperation(value = "出库单重发", notes = "出库单重发")
    @PostMapping("resend")
	public EdiResponse resend(@RequestBody List<ApiOrders> list) {
		try {
			for (ApiOrders dto : list) {
				plApiOrdersService.updateApiOrders("ris_edi",dto);
			}
			return EdiResponse.success();
		} catch (Exception e) {
			return EdiResponse.failed().returnMgr(e.getMessage());
		}
		
	}
	
	@ApiOperation(value = "标记成功", notes = "标记成功")
    @PostMapping("marksucc")
	public EdiResponse markSuccApiOrder(@RequestBody List<ApiOrders> list) {
		try {
			for (ApiOrders dto : list) {
				plApiOrdersService.updateSuccess("ris_edi", dto);
			}
			return EdiResponse.success();
		} catch (Exception e) {
			return EdiResponse.failed().returnMgr(e.getMessage());
		}
	}
}
